package com.itcast.mongo;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * Created by Administrator on 2016/1/19 0019.
 */
public class Test {

    public static void main(String[] args) {


        ApplicationContext ctx = new GenericXmlApplicationContext(
                "classpath*:spring/spring-mongo.xml");
//        mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
//        Query logQuery = new Query(Criteria.where("userName").is("15920564512"));
//
//        Assert.assertNotNull(logVo);
        //首先连接mongodb服务器
//        Mongo m = new Mongo("localhost", 27017);
//
//        DB db = m.getDB("iris");
//
//        DBCollection dbcol = db.getCollection("data_1234");
//
//        System.out.println("数据量为" + dbcol.count());
//
//        //下面查询mongodb中的iris数据库，对data_1234这个表中的数据进行模糊查询打印到控制台上
//        Query query = new Query();
//        query.addCriteria(Criteria.where("reportId").is("nihao"));
//        dbcol.count();
//
//        //最后如果查询到数据生成excel文件 保存两个字段，链接和涉及关键字

    }
}
